Finite Markov Chains


In [9]:
P = [.4 .6; .2 .8]
psi = [0.25, 0.75]
psi' * P


Out[9]:
1x2 Array{Float64,2}:
 0.25  0.75

In [10]:
P' * psi


Out[10]:
2-element Array{Float64,1}:
 0.25
 0.75

In [11]:
psi'


Out[11]:
1x2 Array{Float64,2}:
 0.25  0.75

In [12]:
using PyPlot
using QuantEcon: mc_compute_stationary

P =[0.971 0.029 0.000
    0.145 0.778 0.077
    0.000 0.508 0.492]

psi = [0.0 0.2 0.8]

fig = figure()
ax = fig[:gca](projection="3d")
ax[:set_xlim](0, 1)
ax[:set_ylim](0, 1)
ax[:set_zlim](0, 1)
ax[:set_xticks]((0.25, 0.5, 0.75))
ax[:set_yticks]((0.25, 0.5, 0.75))
ax[:set_zticks]((0.25, 0.5, 0.75))

t = 20
x_vals = Array(Float64, t)
y_vals = Array(Float64, t)
z_vals = Array(Float64, t)

for i=1:t
    x_vals[i] = psi[1]
    y_vals[i] = psi[2]
    z_vals[i] = psi[3]
    psi = psi*P
end

ax[:scatter](x_vals, y_vals, z_vals, c="r", s = 60)

P = MarkovChain(P)
psi_star = mc_compute_stationary(P)
ax[:scatter](psi_star[1], psi_star[2], psi_star[3], c="k", s = 60)


INFO: Precompiling module PyPlot...
Assertion failed: (ctx->gensym_assigned.at(idx)), function emit_expr, file codegen.cpp, line 3155.

signal (6): Abort trap: 6
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
ERROR: LoadError: Failed to precompile PyCall to /Users/akira/.julia/lib/v0.4/PyCall.ji
 in error at /usr/local/Cellar/julia/0.4.6_1/lib/julia/sys.dylib
 in compilecache at loading.jl:400
 in require at /usr/local/Cellar/julia/0.4.6_1/lib/julia/sys.dylib
 in include at /usr/local/Cellar/julia/0.4.6_1/lib/julia/sys.dylib
 in include_from_node1 at /usr/local/Cellar/julia/0.4.6_1/lib/julia/sys.dylib
 [inlined code] from none:2
 in anonymous at no file:0
 in process_options at /usr/local/Cellar/julia/0.4.6_1/lib/julia/sys.dylib
 in _start at /usr/local/Cellar/julia/0.4.6_1/lib/julia/sys.dylib
while loading /Users/akira/.julia/v0.4/PyPlot/src/PyPlot.jl, in expression starting on line 5
LoadError: Failed to precompile PyPlot to /Users/akira/.julia/lib/v0.4/PyPlot.ji
while loading In[12], in expression starting on line 1

 in error at /usr/local/Cellar/julia/0.4.6_1/lib/julia/sys.dylib
 in compilecache at loading.jl:400
 in require at /usr/local/Cellar/julia/0.4.6_1/lib/julia/sys.dylib

In [ ]: